<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-descriptions
          title="订单信息"
          :column="2"
        >
          <el-descriptions-item label="订单编号">{{data.orderNumber}}</el-descriptions-item>
          <el-descriptions-item label="学生">{{ data.userName }}</el-descriptions-item>
          <el-descriptions-item label="学生电话">{{  data.userPhone}}</el-descriptions-item>
          <el-descriptions-item label="教师">{{ data.tutorName }}</el-descriptions-item>
          <el-descriptions-item label="教师电话">{{  data.tutorPhone}}</el-descriptions-item>
          <el-descriptions-item label="创建时间">{{ data.createdAt }}</el-descriptions-item>
          <el-descriptions-item label="状态">{{ data.status }}</el-descriptions-item>
          <el-descriptions-item label="金额"><el-tag>{{  data.totalFee}}</el-tag></el-descriptions-item>
        </el-descriptions>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-descriptions
          title="评价"
          :column="1"
        >
          <el-descriptions-item label="评分">
            <el-rate v-model="form.rating"></el-rate>
          </el-descriptions-item>
          <el-descriptions-item label="内容">
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="form.comment"
            ></el-input>
          </el-descriptions-item>
        </el-descriptions>
      </el-col>
    </el-row>
    <div style="text-align: right">
      <el-button
        type="primary"
        @click="submit"
      >{{ form.id?"修改":"提交"}}</el-button>
    </div>

  </div>

</template>

<script>
import {
  listOrders,
  getOrders,
  delOrders,
  addOrders,
  updateOrders,
} from '@/api/system/orders'
import { listReviews, addReviews, updateReviews } from '@/api/system/reviews'
export default {
  props: {
    value: Number,
  },
  watch: {
    value: {
      handler(val) {
        if (val) {
          this.getData()
        }
      },
      deep: true,
      immediate: true,
    },
  },
  data() {
    return {
      data: {},
      form: {},
    }
  },
  methods: {
    submit() {
      if (this.form.rating == 0 || this.form.rating) {
        if (!this.form.id) {
          addReviews(this.form).then(() => {
            updateOrders({ ...this.data, status: '已评价' }).then((v) => {
              this.$modal.msgSuccess('评价成功！')
              this.form = {}
              this.$emit('close')
            })
          })
        } else {
          updateReviews(this.form).then(() => {
            this.$modal.msgSuccess('评价成功！')
            this.form = {}
            this.$emit('close')
          })
        }
      }
    },
    getData() {
      getOrders(this.value).then((res) => {
        this.data = res.data
        listReviews({ orderId: res.data.id }).then((v) => {
          if (v.rows && v.rows.length) {
            this.form = v.rows[0]
          } else {
            this.form.orderId = res.data.id
            this.form.userId = res.data.tutorId
          }
          console.log( this.form,6666);
          
        })
      })
    },
  },
}
</script>

<style>
</style>